//
//  ChangePswViewController.m
//  WangLottery
//
//  Created by 黄修勇 on 12-5-14.
//  Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
//

#import "ChangePswViewController.h"

@interface ChangePswViewController ()

@end

@implementation ChangePswViewController


@synthesize oldPswTextFiled=_oldPswTextFiled;
@synthesize newPswTextFiled=_newPswTextFiled;
@synthesize verPswTextFiled=_verPswTextFiled;


-(void)dealloc{

    
    [_oldPswTextFiled release];
    [_newPswTextFiled release];
    [_verPswTextFiled release];
    [super dealloc];
}



- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    self.title=@"修改密码";
    // Do any additional setup after loading the view from its nib.
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}
#pragma mark -

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    return 3;
}


-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    //因为数量比较少不用重用
    
    UITableViewCell *cell=[[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"change psw"] autorelease];
     cell.selectionStyle=UITableViewCellSelectionStyleNone;
    cell.backgroundColor=[UIColor colorWithRed:1.0f green:1.0f blue:1.0f alpha:0.4f];
    
    UIFont *font=[UIFont systemFontOfSize:14.0f];
    UILabel *titleLabel=[[UILabel alloc]initWithFrame:CGRectMake(20.0f, 45.0f/2-31.0f/2, 60.0f, 31.0f)];
    titleLabel.backgroundColor=[UIColor clearColor];
    titleLabel.font=font;
    [cell.contentView addSubview:titleLabel];
    
    
    UITextField *textFiled=[[UITextField alloc]initWithFrame:CGRectMake(90.0f, titleLabel.frame.origin.y+8.0f, 200.0f, 31.0f)];
    textFiled.delegate=self;
    textFiled.font=font;
    textFiled.clearButtonMode=UITextFieldViewModeWhileEditing;
    textFiled.returnKeyType=UIReturnKeyDone;
    [cell.contentView addSubview:textFiled];
    textFiled.secureTextEntry=YES;
    
    
    switch (indexPath.row) {
        case 0:
            titleLabel.text=@"原密码";
            textFiled.placeholder=@"原始密码";
            self.oldPswTextFiled=textFiled;
            break;
        case 1:
            titleLabel.text=@"新密码";
            textFiled.placeholder=@"8－20位数字或字母";
            self.newPswTextFiled=textFiled;
            break;
        case 2:
            titleLabel.text=@"确认密码";
            textFiled.placeholder=@"再次输入密码";
            self.verPswTextFiled=textFiled;
            textFiled.returnKeyType=UIReturnKeyDone;
            break;
        default:
            break;
    }
    
    
    [titleLabel release];
    [textFiled release];
    
    
    return cell;
    
}

-(BOOL)textFieldShouldReturn:(UITextField *)textField{

    [textField resignFirstResponder];
    return YES;
}
#pragma mark-

-(IBAction)changeBtnDone:(id)sender{

    if (_oldPswTextFiled.text==nil||[_oldPswTextFiled.text isEqualToString:@""]) {
        [self showAlertViewWithTitle:@"提示" msg:@"旧密码不能为空!"];
        return;
    }
    
    if (_newPswTextFiled.text.length<8) {
        [self showAlertViewWithTitle:@"提示" msg:@"新密码不能小于八位!"];
        return;
    }
    
    if ([_newPswTextFiled.text isEqualToString:_verPswTextFiled.text]) {
        [self showAlertViewWithTitle:@"提示" msg:@"两次输入的密码不一致!"];
        return;
    }
}

@end
